package com.qianduo.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import com.qianduo.dao.IQianduoProductDao;
import com.qianduo.po.QianduoProduct;
import com.qianduo.po.QianduoProductView;
import com.qianduo.util.Constants;
import com.qianduo.util.ServiceUtil;
import com.qianduo.vo.QianduoProductForm;

import common.page.PageList;
import common.util.ObjectUtil;

@SuppressWarnings("finally")
public class QianduoProductServiceImpl extends ServiceUtil{
	private IQianduoProductDao qianduoProductDao;
	
	
	public IQianduoProductDao getQianduoProductDao() {
		return qianduoProductDao;
	}

	public void setQianduoProductDao(IQianduoProductDao qianduoProductDao) {
		this.qianduoProductDao = qianduoProductDao;
	}
	
	public boolean saveOrUpdateProduct(QianduoProductForm vo){
		boolean ret		= false;
		try{
			QianduoProduct po	= new QianduoProduct();
			ObjectUtil.copyProperties(po, vo);
			qianduoProductDao.saveOrUpdateProduct(po);
			
			ret		= true;
		}catch(Exception e){
			Constants.log.error(className+" saveOrUpdateProduct",e);
		}finally{
			return ret;
		}
	}
	
	public List<QianduoProductForm> listProduct(Integer id,Integer type,Integer agencyID,String name,BigDecimal amount,Integer period,BigDecimal rate,String createDateStart,String createDateEnd,PageList pageList){
		List<QianduoProductForm> retList	= null;
		try{
			List<QianduoProductView> listPO	= qianduoProductDao.listProduct(id, type, agencyID, name, amount, period, rate, createDateStart, createDateEnd, pageList);
			if(null != listPO && listPO.size() > 0){
				retList = new ArrayList<QianduoProductForm>();
				for(QianduoProductView po : listPO){
					QianduoProductForm vo = new QianduoProductForm();
					ObjectUtil.copyProperties(vo, po);
					
					retList.add(vo);
				}
			}
		}catch(Exception e){
			Constants.log.error(className+" listProduct",e);
		}finally{
			return retList;
		}
	}
}
